package 笔试.未来.one;

import org.junit.Test;

import java.util.Arrays;

public class Main {
    @Test
    public void test() {
        int[] p = {-10,2};
        System.out.println(firstMissingPositive(p));
    }
    public int firstMissingPositive2 (int[] A) {
        if(A==null || A.length==0)return 0;
        Arrays.sort(A);
        if(A[A.length-1]<0)return 0;
        for (int i = 0; i < A.length-1; i++) {
            if(A[i]>0 && (A[i]+1)<A[i+1]){
                return A[i]+1;
            }
        }
        return A[A.length-1]+1;
    }
    public int firstMissingPositive (int[] A) {
        if(A==null || A.length==0)return 1;
        Arrays.sort(A);
        if(A[A.length-1]<0)return 1;

        for (int i = 0; i < A.length-1; i++) {
            if((A[i]+1)<A[i+1]){
                int res= A[i]+1;
                if(res<=0)return 1;
                else return res;
            }
        }
        return A[A.length-1]+1;
    }
}
